<template>
  <view class="wrap" :data-theme="theme()" :class="theme()" v-if="!loading">
    <Myinfo
      v-if="!ProductData.some((item) => item.orderData.delivery === 30)"
      :Address="Address"
      :existAddress="existAddress"
    ></Myinfo>
    <!--购买的产品-->
    <view class="vender">
      <view class="list">
        <view
          v-for="(supplier_item, supplier_index) in ProductData"
          :key="supplier_index"
        >
          <view class="sup_itemtit" v-if="storeOpen == 1">
            <i class="icon iconfont icon-dianpu1"></i>
            <view class="f26 gray3">
              {{ supplier_item.supplier.name }}
            </view>
          </view>
          <view
            class="item"
            v-for="(item, index) in supplier_item.productList"
            :key="index"
          >
            <view class="d-f">
              <view class="cover">
                <image :src="item.productImage" mode="aspectFit"></image>
              </view>
              <view class="info">
                <view class="d-b-s">
                  <view class="flex-1">
                    <view class="title f32 gray3">{{ item.productName }}</view>
                    <view class="theme-price mt10 f18">
                      ¥<text class="f26">{{ item.productPrice }}</text>
                    </view>
                    <view
                      class="describe mt10 f24"
                      v-if="options.orderType == 'deposit'"
                    >
                      {{ item.advanceSku.productAttr }}
                    </view>
                    <view
                      class="describe mt10 f24"
                      v-else-if="options.orderType == 'retainage'"
                    >
                      {{ item.productAttr }}
                    </view>
                    <view class="describe mt10 f24" v-else
                      >{{ item.productSku.productAttr }}
                    </view>
                  </view>
                  <view>
                    <view class="count_choose">
                      <view class="num-wrap">
                        <view class="f22 tr">×{{ item.totalNum }}</view>
                      </view>
                    </view>
                  </view>
                </view>
              </view>
            </view>
            <view class="mt10 tr f28" v-if="item.isUserGrade">
              <text class="f26">会员折扣价：</text>
              <text class="theme-price f32"
                >￥{{ item.gradeProductPrice }}</text
              >
            </view>
            <view class="mt10 tr f28" v-if="item.productReduceMoney > 0">
              <text class="f26">立减：</text>
              <text class="theme-price f32"
                >￥{{ item.productReduceMoney }}</text
              >
            </view>
          </view>

          <view class="d-f-c" @tap="DistUp(supplier_item)">
            <view v-if="supplier_item.orderData.delivery == 10">
              配送方式 <text class="extp">普通快递</text>
            </view>
            <view v-if="supplier_item.orderData.delivery == 20">
              <view class="info d-s-s" style="padding-left: 0">
                <text class="zt theme-btn">当前自提点</text>
                <view class="province-c-a d-s-s flex-1">
                  <text>{{ storeList[supplier_item.shopSupplierId] }}</text>
                </view>
              </view>
            </view>
            <view v-if="supplier_item.orderData.delivery == 30">
              虚拟商品：无需物流
            </view>
            <view class="dfjac" v-if="supplier_item.orderData.delivery != 30">
              <view v-if="supplier_item.orderData.delivery == 10">
                {{
                  supplier_item.orderData.expressPrice != 0
                    ? "￥ " + supplier_item.orderData.expressPrice
                    : "快递 免费"
                }}
              </view>
              <i class="iconfont icon-jiantou"></i>
            </view>
          </view>
          <template v-if="options.orderType == 'deposit'">
            <view class="d-f-c">
              <text class="key f26">定金：</text>
              <view class="f24">￥{{ OrderData.money }}</view>
            </view>
            <view class="d-f-c">
              <text class="key f26">尾款：</text>
              <view class="f24"> ￥{{ OrderData.balancePayment }}</view>
            </view>
            <view class="f-d-c p30">
              <view class="ww100 d-e-c red"
                >(单件商品尾款已减{{ OrderData.reduceMoney }}元)
              </view>
              <view class="ww100 d-e-c gray9">
                {{ OrderData.advanceEndTime }}支付尾款
                <!-- {{supplier_item.productList[0].advance.active_time[0]}}-{{supplier_item.productList[0].advance.active_time[1]}}支付尾款 -->
              </view>
            </view>
          </template>
          <template v-else>
            <view class="d-f-c" v-if="!OrderData.forcePoints">
              <view class="">优惠券</view>
              <block v-if="objKeys(supplier_item.orderData.couponList, 1) > 0">
                <text
                  class="vlaue theme-price"
                  v-if="supplier_item.orderData.couponMoney > 0"
                  @tap="
                    onTogglePopupCoupon(
                      supplier_item.orderData.couponList,
                      supplier_item
                    )
                  "
                  >-￥{{ supplier_item.orderData.couponMoney }}</text
                >
                <text
                  v-else
                  class="vlaue theme-price"
                  @tap="
                    onTogglePopupCoupon(
                      supplier_item.orderData.couponList,
                      supplier_item
                    )
                  "
                  >有{{
                    objKeys(supplier_item.orderData.couponList, 1)
                  }}张优惠券可用<i class="iconfont icon-jiantou"></i
                ></text>
              </block>
              <text v-else class="f24 gray9">无优惠券可用</text>
            </view>
            <view class="d-f-c" v-if="supplier_item.orderData.reduce">
              <view>商户{{ supplier_item.orderData.reduce.activeName }}</view>
              <view class="theme-price f24">
                -￥{{ supplier_item.orderData.reduce.reducedPrice }}
              </view>
            </view>
            <view
              v-if="
                isUsePoints == 1 &&
                !OrderData.forcePoints &&
                supplier_item.orderData.pointsMoney > 0
              "
            >
              <view class="d-f-c">
                <view>积分抵扣金额</view>
                <view class="theme-price f24"
                  >-￥{{ supplier_item.orderData.pointsMoney }}</view
                >
              </view>
            </view>
            <view class="d-f-c">
              <view class="ww100">
                <view class="mb20">订单备注</view>
                <view class="ww100">
                  <textarea
                    v-model="storeData[supplier_item.shopSupplierId].remark"
                    placeholder="选填,请先和商家协商一致"
                    class="text_area"
                  />
                </view>
              </view>
            </view>
            <!--总数-->
            <view class="total-box vthl">
              <view>
                <text class="f26 gray3"
                  >共{{ supplier_item.productList.length }}件商品,总价:</text
                >
                <text class="f20 gray3">￥</text>
                <text class="f26 gray3">{{
                  supplier_item.orderData.orderTotalPrice
                }}</text>
              </view>
              <view class="d-f">
                <view class="f26" v-if="!settledRule.forcePoints">
                  实付款：<text class="theme-price f20">￥</text
                  ><text class="price theme-price" style="font-size: 32rpx">{{
                    toDecimal2(supplier_item.orderData.orderPayPrice)
                  }}</text>
                </view>
              </view>
            </view>
          </template>
        </view>
      </view>
    </view>
    <!--其它费用-->
    <view class="buy-checkout">
      <view class="item">
        <text class="key f26">订单总金额：</text>
        <view>
          <text class="theme-price f24">￥{{ OrderData.orderTotalPrice }}</text>
        </view>
      </view>
      <view class="item f26" v-if="settledRule.isCoupon">
        <text class="key">平台优惠券：</text>
        <block v-if="couponNum > 0">
          <text
            class="f24 theme-price"
            v-if="OrderData.couponMoneySys > 0"
            @tap="onTogglePopupCoupon(couponList, 0)"
            >-￥{{ OrderData.couponMoneySys }}</text
          >
          <text
            v-else
            class="f24 theme-price"
            @tap="onTogglePopupCoupon(couponList, 0)"
            >有{{ couponNum }}张优惠券可用</text
          >
        </block>
        <text v-else class="f24 gray9">无优惠券可用</text>
      </view>
      <view class="item" v-if="OrderData.productReduceMoney > 0">
        <text class="key">商品立减：</text>
        <view>
          <text class="theme-price f24"
            >-￥{{ OrderData.productReduceMoney }}</text
          >
        </view>
      </view>
      <view
        class="item"
        v-if="
          OrderData.isAllowPoints &&
          settledRule.forcePoints == false &&
          OrderData.pointsMoney != 0
        "
      >
        <text class="key">可用积分抵扣：</text>
        <view class="">
          <text class="theme-price f24"
            >-￥{{ toDecimal2(OrderData.pointsMoney) }}</text
          >
          <switch
            style="transform: scale(0.7); margin-right: -10rpx"
            checked="true"
            @change="onShowPoints"
          />
        </view>
      </view>
    </view>
    <view class="buy-checkout" v-if="confirm && confirm != null">
      <view class="item" v-for="(item, index) in confirm" :key="index">
        <view style="white-space: nowrap">
          <span v-if="item.status" style="color: red">* </span>
          <span v-else style="margin-left: 18rpx"></span>
          <span>{{ item.title }}</span>
        </view>
        <!-- text -->
        <view v-if="item.label == 'text'" class="confirm">
          <input
            type="text"
            :placeholder="'请填写' + item.title"
            v-model="item.value"
          />
        </view>
        <!-- number -->
        <view v-if="item.label == 'number'" class="confirm">
          <input
            type="number"
            :placeholder="'请填写' + item.title"
            v-model="item.value"
          />
        </view>
        <!-- email -->
        <view v-if="item.label == 'email'" class="confirm">
          <input
            type="text"
            :placeholder="'请填写' + item.title"
            v-model="item.value"
          />
        </view>
        <!-- data -->
        <view v-if="item.label == 'data'" class="uni-list">
          <view class="uni-list-cell">
            <view class="uni-list-cell-db">
              <picker
                mode="date"
                :value="item.value"
                @change="bindDateChange($event, index)"
              >
                <view v-if="item.value == ''" class="fontC f24"
                  >{{ date + item.title
                  }}<text class="iconfont icon-jiantou"></text
                ></view>
                <view v-else class="uni-input f24">{{ item.value }}</view>
              </picker>
            </view>
          </view>
        </view>
        <!-- time -->
        <view v-if="item.label == 'time'">
          <view>
            <view>
              <picker
                mode="time"
                :value="item.value"
                start="00:00"
                end="23:59"
                @change="bindTimeChange($event, index)"
              >
                <view v-if="item.value == ''" class="fontC"
                  >{{ time + item.title
                  }}<text class="iconfont icon-jiantou"></text
                ></view>
                <view>{{ item.value }}</view>
              </picker>
            </view>
          </view>
        </view>
        <!-- id -->
        <view v-if="item.label == 'id'" class="confirm">
          <input
            type="idcard"
            :placeholder="'请填写' + item.title"
            v-model="item.value"
          />
        </view>
        <!-- phone -->
        <view v-if="item.label == 'phone'" class="confirm">
          <input
            type="tel"
            :placeholder="'请填写' + item.title"
            v-model="item.value"
          />
        </view>
        <!-- img -->
        <view v-if="item.label == 'img'" class="confirmImg">
          <view class="upload-list d-s-c">
            <view
              class="itemss"
              style="height: 136rpx"
              v-for="(imgs, img_num) in item.value"
              :key="img_num"
              @click="deleteImg(index, img_num)"
            >
              <image :src="imgs.filePath" mode=""></image>
            </view>
            <view
              style="height: 136rpx"
              class="item upload-btn d-c-c d-c"
              @click="openUpload(index)"
              v-if="item.value.length < 9"
            >
              <text class="icon iconfont icon-xiangji"></text>
              <text class="gray9">上传图片</text>
            </view>
          </view>
        </view>
      </view>
    </view>
    <!--底部支付-->
    <view class="foot-pay-btns">
      <template v-if="options.orderType == 'deposit'">
        <view>
          应付
          <text class="fb theme-price">¥</text>
          <text class="num theme-price fb f38">{{ payDeposit() }}</text>
        </view>
      </template>
      <template v-else>
        <view class="price" v-if="!settledRule.forcePoints">
          ¥
          <text class="num">{{ OrderData.orderPayPrice }}</text>
        </view>
        <view class="price" v-if="settledRule.forcePoints">
          <text class="gray9">所需积分</text>
          <text class="num theme-price fb">{{
            ProductData[0].orderData.pointsNum
          }}</text>
          <template v-if="OrderData.orderPayPrice > 0">
            <text class="theme-price">+</text>
            <text class="theme-price">¥</text>
            <text class="num fb theme-price">{{
              OrderData.orderPayPrice
            }}</text>
          </template>
        </view>
      </template>
      <!-- #ifdef  H5 -->
      <template v-if="isWeixin() && mpState == 1 && temlIds.length > 0">
        <wx-open-subscribe
          :template="temlIds"
          id="subscribe-btn"
          @success="subscribeSuccess"
          @error="subscribeFail"
          :style="{
            width: btnAtrrpx.width + 'px',
          }"
        >
          <div v-is="'script'" type="text/wxtag-template" slot="style">
            <div v-is="'style'">
              .subscribe-btn.theme0{ background: #ff5704; }
              .subscribe-btn.theme1{ background: #19ad57; }
              .subscribe-btn.theme2{ background: #ffcc00; }
              .subscribe-btn.theme3{ background: #33a7ff; }
              .subscribe-btn.theme4{ background: #e4e4e4; }
              .subscribe-btn.theme5{ background: #c8ba97; }
              .subscribe-btn.theme6{ background: #623ceb; } .subscribe-btn {
              display:flex; width:100%; align-items:center;
              justify-content:center; color: #fff; border:none; }
            </div>
          </div>
          <div v-is="'script'" type="text/wxtag-template">
            <div
              class="subscribe-btn"
              :class="theme()"
              :style="{
                height: btnAtrrpx.height + 'px',
                lineHeight: btnAtrrpx.height + 'px',
                borderRadius: btnAtrrpx.borderRadius + 'px',
                fontSize: btnAtrrpx.fontSize + 'px',
              }"
            >
              提交订单
            </div>
          </div>
        </wx-open-subscribe>
      </template>
      <template v-else>
        <button @click="SubmitOrder">提交订单</button>
      </template>
      <!-- #endif -->
      <!-- #ifndef  H5 -->
      <button @click="SubmitOrder">提交订单</button>
      <!-- #endif -->
    </view>
    <!-- 上传头像 -->
    <Upload v-if="isUpload" :num="1" @getImgs="getImgsFunc"></Upload>
    <!--优惠券-->
    <Coupon
      :isCoupon="isCoupon"
      :couponList="couponList"
      @close="closeCouponFunc"
    ></Coupon>
    <Dist
      :isDist="isDist"
      :chooseSotr="chooseSotr"
      @close="closeDistFunc"
      :extractStore="extractStore"
      :lastExtract="lastExtract"
      :deliverySetting="deliverySetting"
    ></Dist>
  </view>
</template>

<script>
import uniPopup from "@/components/uni-popup.vue";
import Myinfo from "./confirm-order/my-info.vue";
import Coupon from "./confirm-order/coupon.vue";
import Dist from "./confirm-order/distr.vue";
import Upload from "@/components/upload/upload.vue";
import { pay } from "@/common/pay.js";
// import { utils } from "@/utils/util.js";
export default {
  components: {
    Myinfo,
    Coupon,
    Dist,
    Upload,
    // utils,
  },
  data() {
    return {
      confirm: "",
      /*是否加载完成*/
      loading: true,
      isUpload: false,
      options: {},
      indicatorDots: true,
      autoplay: true,
      interval: 2000,
      duration: 500,
      /*商品id*/
      product_id: "",
      /*商品数量*/
      product_num: "",
      /*商品数据*/
      ProductData: [],
      /*订单数据数据*/
      OrderData: [],
      // 是否存在收货地址
      existAddress: false,
      /*默认地址*/
      Address: {
        region: [],
      },
      extractStore: [],
      lastExtract: {},
      productSkuId: 0,
      /*配送方式*/
      delivery: 10,
      /*自提店id*/
      storeId: 0,
      /*优惠券id*/
      couponId: -1,
      /*是否使用积分,默认使用*/
      isUsePoints: 1,
      remark: "",
      /*支付方式*/
      pay_type: 20,
      /*是否显示优惠券*/
      isCoupon: false,
      /*优惠券列表*/
      platformCouponList: {},
      // 商家优惠券
      couponList: [],
      /*优惠券数量*/
      couponNum: 0,
      /* 是否显示配送方式 */
      isDist: false,
      /*消息模板*/
      temlIds: [],
      productCouponid: 0,
      chooseSotr: 0,
      /* 支持的配送方式 */
      deliverySetting: [],
      chooseDelivery: 10,
      storeData: {},
      // 当前店铺选择的门店
      chooseStoreId: 0,
      storeList: {},
      balance: "",
      date: "请选择",
      time: "请选择",
      defaultDate: "",
      defaultTime: "",
      /* 
				//是否显示店铺信息,1显示，0隐藏
				private Integer storeOpen;
				 */
      storeOpen: 1,
      settledRule: {},
      roomId: 0,
      imageurl: "",
      // 1 公众号登录
      mpState: null,
    };
  },
  onLoad(options) {
    let mpState = uni.getStorageSync("mpState");
    this.mpState = mpState;
    let self = this;
    // 公众号分享
    if (this.getPlatform() == "mp") {
      this.url = window.location.href;
    }
    self.options = options;
    self.roomId = options.roomId || 0;
    console.log("--roomid1--", options.roomId);
    self.$fire.on("selectStoreId", function (e) {
      self.extractStore = e;
      self.chooseStoreId = e.storeId;
    });
    self.$fire.on("checkedfir", function (n) {
      self.chooseDelivery = n;
    });
    let btnAtrrpx = {
      height: 80,
      borderRadius: 40,
      fontSize: 32,
      width: 200,
    };
    uni.getSystemInfo({
      success: function (res) {
        let scale = res.screenWidth / 750;
        let newObj = {};
        for (let key in btnAtrrpx) {
          newObj[key] = btnAtrrpx[key] * scale;
        }
        self.btnAtrrpx = newObj;
      },
      fail() {
        self.btnAtrrpx = btnAtrrpx;
      },
    });
    this.defaultDate = this.getCurrentDate();
    this.defaultTime = this.getCurrentTime();
    console.log(this.defaultDate, "defaultDate");
  },
  onShow() {
    this.getData();
    //#ifdef H5
    this.getTemplateId();
    //#endif
  },
  mounted() {},
  methods: {
    openUpload(index) {
      this.index = index;
      this.isUpload = true;
    },
    /*获取上传的图片*/
    getImgsFunc(e) {
      let self = this;
      if (e && typeof e != "undefined") {
        let index = self.index;
        self.confirm[index].value = self.confirm[index].value.concat(e);
      }
      self.isUpload = false;
    },

    /*点击图片删除*/
    deleteImg(i, n) {
      this.confirm[i].value.splice(n, 1);
    },
    // 获取当前日期
    getCurrentDate() {
      const currentDate = new Date();
      const year = currentDate.getFullYear();
      const month = String(currentDate.getMonth() + 1).padStart(2, "0");
      const day = String(currentDate.getDate()).padStart(2, "0");
      return `${year}-${month}-${day}`;
    },
    // 获取当前时间
    getCurrentTime() {
      const currentTime = new Date();
      const hours = String(currentTime.getHours()).padStart(2, "0");
      const minutes = String(currentTime.getMinutes()).padStart(2, "0");
      const seconds = String(currentTime.getSeconds()).padStart(2, "0");
      return `${hours}:${minutes}:${seconds}`;
    },
    subscribeSuccess() {
      this.SubmitOrder();
      console.log("调用成功");
    },
    subscribeFail() {
      this.SubmitOrder();
      console.log("调用失败");
    },
    payDeposit() {
      return (
        parseFloat(this.OrderData.money) +
        ((this.orderData && this.orderData.expressPrice) || 0)
      );
    },
    init() {
      let key = "";
      let value = "";
      let self = this;
      self.ProductData.forEach((item, index) => {
        key = item.shopSupplierId;
        value = {
          couponId: item.orderData.couponId,
          delivery: item.orderData.delivery,
          storeId: 0,
          remark: "",
        };
        self.storeData = {
          ...self.storeData,
          [key]: value,
        };
      });
      console.log(self.storeData);
    },
    /**/
    hasType(e) {
      if (this.deliverySetting.indexOf(e) != -1) {
        return true;
      } else {
        return false;
      }
    },
    formpost(url, postData) {
      let tempform = document.createElement("form");
      tempform.action = url;
      tempform.method = "post";
      tempform.target = "_self";
      tempform.style.display = "none";
      for (let x in postData) {
        let opt = document.createElement("input");
        opt.name = x;
        opt.value = postData[x];
        tempform.appendChild(opt);
      }
      document.body.appendChild(tempform);
      this.$nextTick((e) => {
        tempform.submit();
      });
    },
    bindDateChange: function (e, index) {
      console.log(e, "e");
      this.confirm[index].value = e.detail.value;
    },
    bindTimeChange: function (e, index) {
      this.confirm[index].value = e.detail.value;
    },
    getDate(type) {
      const date = new Date();
      let year = date.getFullYear();
      let month = date.getMonth() + 1;
      let day = date.getDate();

      if (type === "start") {
        year = year - 60;
      } else if (type === "end") {
        year = year + 2;
      }
      month = month > 9 ? month : "0" + month;
      day = day > 9 ? day : "0" + day;
      return `${year}-${month}-${day}`;
    },
    uploadpic: function (index, item) {
      let that = this;
      this.canvasStatus = true;
      that.utils.uploadImageChange(
        "/front/file/upload/image",
        function (res) {
          console.log(res, "res");
          item.value.push(res.data.url);
        },
        (res) => {
          this.canvasStatus = false;
        },
        (res) => {
          this.canvasWidth = res.w;
          this.canvasHeight = res.h;
        }
      );
    },
    DelPic: function (index, indexs) {
      let that = this,
        pic = this.confirm[index].value;
      that.confirm[index].value.splice(indexs, 1);
      // that.$set(that, 'pics', that.pics);
    },
    /*支付方式选择*/
    payTypeFunc(e) {
      this.pay_type = e;
    },
    /*是否使用积分选择*/
    onShowPoints: function (e) {
      let self = this;
      if (e.detail.value == true) {
        self.isUsePoints = 1;
      } else {
        self.isUsePoints = 0;
      }
      self.getData();
    },
    /*选择优惠卷*/
    onTogglePopupCoupon(e, id) {
      let self = this;
      if (id != 0) {
        self.chooseSotr = id.shopSupplierId;
      } else {
        self.chooseSotr = 0;
      }
      self.isCoupon = true;
      self.couponList = e;
    },
    /*关闭优惠券*/
    closeCouponFunc(e) {
      let self = this;
      if (e && typeof e != "number") {
        self.isCoupon = false;
        return;
      }
      if (self.chooseSotr != 0) {
        let storid = self.chooseSotr;
        if (e > 0) {
          self.storeData[storid].couponId = e;
        } else {
          self.storeData[storid].couponId = 0;
        }
        self.chooseSotr = 0;
      } else {
        if (e > 0) {
          self.couponId = e;
        } else {
          self.couponId = 0;
        }
      }
      self.isCoupon = false;
      self.getData();
    },
    /*获取数据*/
    getData() {
      let self = this;
      uni.showLoading({
        title: "加载中",
      });

      let callback = function (res) {
        self.OrderData = res.data.orderData;
        self.temlIds = res.data.templateArr;
        self.ProductData = res.data.supplierList;
        self.existAddress = self.OrderData.existAddress;
        self.Address = self.OrderData.address;
        self.ProductData.forEach((product) => {
          product.productList.forEach((c) => {
            self.confirm = c.customForm;
          });
        });
        if (self.confirm) {
          self.confirm.map((e) => {
            if (e.label === "img") e.value = [];
          });
        }
        self.lastExtract = self.OrderData.lastExtract;
        if (self.options.orderType != "deposit") {
          self.couponList = self.OrderData.couponList;
          self.couponId = self.OrderData.couponIdSys;
          self.couponNum = 0;
          if (self.couponList) {
            self.couponNum = Object.keys(self.couponList).length;
          }
        }
        self.settledRule = res.data.settledRule;
        if (res.data.orderData.couponList) {
          self.couponList = res.data.orderData.couponList;
        }
        console.log("1111", self.couponList);
        self.couponId = self.OrderData.couponIdSys;
        if (self.couponList != null) {
          self.couponNum = Object.keys(self.couponList).length;
        }

        //#ifdef MP-WEIXIN
        self.storeOpen = res.data.storeOpen;
        //#endif
        if (self.OrderData.orderPayPrice == 0) {
          self.pay_type = 10;
        }
        if (JSON.stringify(self.storeData) == "{}") {
          self.init();
        }
        self.loading = false;
      };

      // 请求的参数
      let params = {
        delivery: self.delivery,
        storeId: self.storeId,
        couponId: self.couponId,
        isUsePoints: self.isUsePoints,
        paySource: self.getPlatform(),
      };
      if (self.roomId && self.roomId != "undefined") {
        params.roomId = self.roomId;
      } else {
        params.roomId = 0;
      }
      if (JSON.stringify(self.storeData) == "{}") {
        params = params;
      } else {
        params = {
          ...params,
          supplier: self.storeData,
        };
      }
      //直接购买
      if (self.options.orderType === "buy") {
        self._postBody(
          "order/order/toBuy",
          Object.assign({}, params, {
            productId: self.options.productId,
            productNum: self.options.productNum,
            specSkuId: self.options.specSkuId,
          }),
          function (res) {
            callback(res);
          },
          (err) => {
            uni.navigateBack();
          }
        );
      }
      //定金
      else if (self.options.orderType === "deposit") {
        let test = Object.assign({}, params, {
          productId: self.options.productId,
          productNum: self.options.productNum,
          productSkuId: self.options.productSkuId,
          advanceProductSkuId: self.options.advanceProductSkuId,
          advanceProductId: self.options.advanceProductId,
        });
        console.log(test);
        self._postBody(
          "plus/advance/order/frontBuy",
          test,
          function (res) {
            callback(res);
          },
          (err) => {
            uni.navigateBack();
          }
        );
      }
      // 购物车结算
      else if (self.options.orderType === "cart") {
        self._postBody(
          "order/order/toCart",
          Object.assign({}, params, {
            cartIds: self.options.cartIds || 0,
          }),
          function (res) {
            callback(res);
          },
          (err) => {
            //uni.navigateBack()
            uni.switchTab({
              url: "/pages/cart/cart",
            });
            //地址错误，跳转我的地址页面
            // uni.navigateTo({
            //   url:"/pages/user/address/address?source=order"
            // })
          }
        );
      }
      // 积分兑换结算
      else if (self.options.orderType == "points") {
        console.log(self.options);
        self._postBody(
          "plus/points/order/toBuy",
          Object.assign({}, params, {
            pointProductId: self.options.pointProductId,
            pointProductSkuId: self.options.pointProductSkuId,
            productSkuId: self.options.productSkuId,
            productNum: self.options.productNum,
          }),
          function (res) {
            callback(res);
          },
          (err) => {
            uni.navigateBack();
          }
        );
      }
      // 限时秒杀
      else if (self.options.orderType === "seckill") {
        self._postBody(
          "plus/seckill/order/toBuy",
          Object.assign({}, params, {
            seckillProductId: self.options.seckillProductId,
            productSkuId: self.options.productSkuId,
            seckillProductSkuId: self.options.seckillProductSkuId,
            productNum: self.options.productNum,
          }),
          function (res) {
            callback(res);
          },
          (err) => {
            uni.navigateBack();
          }
        );
      }
      //砍价
      else if (self.options.orderType === "bargain") {
        self._postBody(
          "plus/bargain/order/toBuy",
          Object.assign({}, params, {
            bargainProductId: self.options.bargainProductId,
            productSkuId: self.options.productSkuId,
            bargainProductSkuId: self.options.bargainProductSkuId,
            bargainTaskId: self.options.bargainTaskId,
          }),
          function (res) {
            callback(res);
          },
          (err) => {
            uni.navigateBack();
          }
        );
      }
      //拼团
      else if (self.options.orderType === "assemble") {
        self._postBody(
          "plus/assemble/order/toBuy",
          Object.assign({}, params, {
            assembleProductId: self.options.assembleProductId,
            productSkuId: self.options.productSkuId,
            assembleProductSkuId: self.options.assembleProductSkuId,
            productNum: self.options.productNum,
            assembleBillId: self.options.assembleBillId,
          }),
          function (res) {
            callback(res);
          },
          (err) => {
            uni.navigateBack();
          }
        );
      }
    },

    getTemplateId() {
      let self = this;
      self._postBody(
        "index/getSignPackage",
        {
          url: self.url,
          paySource: self.getPlatform(),
        },
        function (res) {
          self.mpMessage(res.data.signPackage);
        }
      );
    },

    toDecimal2(x) {
      var f = parseFloat(x);
      if (isNaN(f)) {
        return "0.00";
      }
      var f = Math.round(x * 100);
      var n = Math.round(x * 1000);
      var r = n.toString().split("");
      r = r[r.length - 1];
      if (r >= 5) {
        f = (f - 1) / 100;
      } else {
        f = f / 100;
      }
      var s = f.toString();
      var rs = s.indexOf(".");
      if (rs < 0) {
        rs = s.length;
        s += ".";
      }
      while (s.length <= rs + 2) {
        s += "0";
      }
      return s;
    },
    /* 配送选择 */
    DistUp(item) {
      if (item.orderData.delivery == 30) {
        return;
      }
      let self = this;
      self.storeId = item.shopSupplierId;
      self.chooseSotr = item.shopSupplierId;
      self.chooseDelivery = item.orderData.delivery;
      self.deliverySetting = item.orderData.deliverySetting;
      if (item.orderData.extractStore == null) {
        self.extractStore = {};
      } else {
        self.extractStore = item.orderData.extractStore;
      }
      self.isDist = true;
    },
    /* 关闭配送选择 */
    closeDistFunc(e) {
      let self = this;
      self.chooseDelivery = e;
      self.isDist = false;
      let storname = "";
      if (self.extractStore.region) {
        storname =
          self.extractStore.province +
          self.extractStore.city +
          self.extractStore.region +
          self.extractStore.storeName;
      }
      let storid = self.chooseSotr;
      let chooseStoreId = self.chooseStoreId;

      self.delivery = self.chooseDelivery;
      self.storeId = storid;
      self.storeData[storid].storeId = chooseStoreId;
      self.storeData[storid].delivery = self.chooseDelivery;
      self.storeList[storid] = storname;
      self.chooseSotr = 0;
      self.getData();
    },
    objKeys(obj, n) {
      if (obj) {
        if (n == 1) {
          return Object.keys(obj).length;
        } else {
          return Object.keys(obj);
        }
      }
    },
    /*提交订单*/
    SubmitOrder() {
      let self = this;
      if (
        self.existAddress ||
        self.ProductData.some((item) => item.orderData.delivery == 30)
      ) {
        uni.showLoading({
          title: "加载中",
          mask: true,
        });
        console.log("提交订单");
        console.log(self.confirm, "confirmsss");
        if (this.confirm) {
          for (var i = 0; i < this.confirm.length; i++) {
            console.log(this.confirm[i], "confirm");
            let self = this.confirm[i];
            console.log(self, "self");
            if (self.status) {
              if (
                self.label === "text" ||
                self.label === "data" ||
                self.label === "time" ||
                self.label === "id"
              ) {
                if (!self.value.trim()) {
                  return uni.showToast({
                    title: `请输入` + `${self.title}`,
                    icon: "none",
                  });
                }
              }
              if (self.label === "number") {
                if (self.value <= 0) {
                  return uni.showToast({
                    title: `请输入` + `${self.title}`,
                    icon: "none",
                  });
                }
              }
              if (self.label === "email") {
                if (
                  !/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(
                    self.value
                  )
                ) {
                  return uni.showToast({
                    title: `请输入正确的` + `${self.title}`,
                    icon: "none",
                  });
                }
              }
              if (self.label === "phone") {
                if (!/^1(3|4|5|7|8|9|6)\d{9}$/i.test(self.value)) {
                  return uni.showToast({
                    title: `请输入正确的` + `${self.title}`,
                    icon: "none",
                  });
                }
              }
              if (self.label === "img") {
                if (!self.value.length > 0) {
                  return uni.showToast({
                    title: `请上传` + `${self.title}`,
                    icon: "none",
                  });
                }
              }
            }
          }
        }

        let params = {
          couponId: self.couponId,
          isUsePoints: self.isUsePoints,
          customForm: self.confirm,
        };
        if (self.roomId && self.roomId != "undefined") {
          params.roomId = self.roomId;
        } else {
          params.roomId = 0;
        }
        console.log("--roomid-", self.roomId);
        params = Object.assign(params, {
          supplier: self.storeData,
        });

        // 创建订单-直接下单
        let url = "";
        if (self.options.orderType === "buy") {
          url = "order/order/buy";
          params = Object.assign(params, {
            productId: self.options.productId,
            productNum: self.options.productNum,
            specSkuId: self.options.specSkuId,
          });
        }
        if (self.options.orderType === "deposit") {
          url = "plus/advance/order/buy";
          params = Object.assign(params, {
            productId: self.options.productId,
            productNum: self.options.productNum,
            productSkuId: self.options.productSkuId,
            advanceProductSkuId: self.options.advanceProductSkuId,
            advanceProductId: self.options.advanceProductId,
          });
        }
        // 创建订单-购物车结算
        if (self.options.orderType === "cart") {
          url = "order/order/cart";
          params = Object.assign(params, {
            cartIds: self.options.cartIds || 0,
          });
        }

        // 创建订单-积分兑换
        if (self.options.orderType === "points") {
          url = "plus/points/order/buy";
          params = Object.assign(params, {
            pointProductId: self.options.pointProductId,
            pointProductSkuId: self.options.pointProductSkuId,
            productSkuId: self.options.productSkuId,
            productNum: self.options.productNum,
          });
        }
        // 创建订单-限时秒杀
        if (self.options.orderType === "seckill") {
          url = "plus/seckill/order/buy";
          params = Object.assign(params, {
            seckillProductId: self.options.seckillProductId,
            productSkuId: self.options.productSkuId,
            seckillProductSkuId: self.options.seckillProductSkuId,
            productNum: self.options.productNum,
          });
        }
        // 创建订单-砍价
        if (self.options.orderType === "bargain") {
          url = "plus/bargain/order/buy";
          params = Object.assign(params, {
            bargainProductId: self.options.bargainProductId,
            productSkuId: self.options.productSkuId,
            bargainProductSkuId: self.options.bargainProductSkuId,
            bargainTaskId: self.options.bargainTaskId,
          });
        }

        // 创建订单-限时拼团
        if (self.options.orderType === "assemble") {
          url = "plus/assemble/order/buy";
          params = Object.assign(params, {
            assembleProductId: self.options.assembleProductId,
            productSkuId: self.options.productSkuId,
            assembleProductSkuId: self.options.assembleProductSkuId,
            assembleBillId: self.options.assembleBillId,
            productNum: self.options.productNum,
          });
        }

        let callback = function () {
          console.log("回调");
          self._postBody(url, params, function (res) {
            let ids;
            let pages;
            if (self.options.orderType == "deposit") {
              pages = "/pages/order/cashier?orderType=50&orderId=" + res.data;
            } else if (self.options.orderType == "retainage") {
              ids = res.data;
              pages = "/pages/order/cashier?orderType=10&orderId=" + ids;
            } else {
              if (Array.isArray(res.data)) {
                ids = encodeURIComponent(res.data.join(","));
              } else {
                ids = res.data;
              }

              pages = "/pages/order/cashier?orderType=10&orderId=" + ids;
            }
            self.gotoPage(pages, "redirect");
          });
        };

        self.subMessage(self.temlIds, callback);
      } else {
        uni.showToast({
          title: "请选择配送地址",
        });
      }
    },
  },
};
</script>

<style lang="scss">
.info-image {
  width: 112rpx;
  height: 112rpx;
  border-radius: 10rpx;

  image {
    width: 112rpx;
    height: 112rpx;
    border-radius: 10rpx;
  }
}

.weixinBtn {
  float: right;
}

page {
  background-color: #f2f2f2;
}

.f-d-c {
  flex-direction: column;
}

.wrap {
  padding-bottom: 110rpx;
}

.d-f-c {
  display: flex;
  justify-content: space-between;
  align-items: center;
  overflow: hidden;
  padding: 30rpx 0;
  margin: 0 30rpx;
  font-size: 24rpx;
  border-bottom: 1rpx solid #eeeeee;
}

.dfjac {
  display: flex;
  align-items: center;
}

.d-txar {
  white-space: nowrap;
  width: 200px;
  margin-right: 34rpx;
}

.extp {
  color: #9e9e9e;
  margin-left: 34rpx;
}

.vender .list .item {
  border-bottom: none;
}

.icon-jiantou {
  margin-left: 15rpx;
}

.icon-dianpu1 {
  margin-right: 15rpx;
  font-size: 28rpx;
  color: #333333;
}

.sup_itemtit {
  padding: 40rpx 30rpx;
  display: flex;
  align-items: center;
}

.vender .total-box {
  height: 87rpx;
  line-height: 87rpx;
  border-bottom: 16rpx solid #f2f2f2;
}

.d-f {
  display: flex;
}

.zt {
  padding: 2rpx 10rpx;
  margin-right: 10rpx;
  border-radius: 8rpx;
  font-size: 22rpx;
}

.icon-box .icon-zhifubao {
  color: #1296db;
  font-size: 50rpx;
}

.icon-dianpu1 {
}

.text_area {
  width: 100%;
  height: 120rpx;
  background: #f2f2f2;
  border-radius: 6rpx;
  padding: 20rpx;
  box-sizing: border-box;
  font-size: 24rpx;
}

.icon-xuanze {
  font-size: 38rpx;
}

.buy-checkout .item {
  padding: 30rpx 0;
  margin: 0 30rpx;
}

.buy-checkout input {
  font-size: 24rpx;
}

.buy-checkout .iconfont.icon-jiantou {
  font-size: 24rpx;
  color: #999;
}

.confirm {
  text-align: right;
  font-size: 22rpx;
}

.buy-checkout .item {
  overflow: hidden;
}

.confirmImg {
  padding-top: 60rpx;
  width: 100%;

  .img {
    width: 136rpx;
    height: 136rpx;
  }

  .pictrue {
    width: 136rpx;
    height: 136rpx;
    box-sizing: border-box;
    margin: 18rpx;
    margin-bottom: 35rpx;
    position: relative;
    font-size: 22rpx;
    color: #bbb;

    .del {
      position: absolute;
      top: 0;
      right: 0;
    }
  }

  .bor {
    border: 1rpx solid #ddd;
  }
}

.itemss {
  margin-right: 20rpx;
  margin-bottom: 20rpx;
  width: 136rpx;

  image {
    width: 136rpx;
    height: 136rpx;
    border-radius: 15rpx;
  }
}

.upload-btn {
  width: 136rpx;
  height: 136rpx;
  margin: 0;
  margin-right: 20rpx;
  margin-bottom: 20rpx;
  box-sizing: border-box;
  display: flex;
  justify-content: center;
  align-items: center;
  flex-direction: column;
}

.order-submission .wrapper {
  background-color: #fff;
  margin-top: 13rpx;
}

.order-submission .wrapper .item {
  padding: 27rpx 30rpx;
  font-size: 30rpx;
  color: #282828;
  border-bottom: 1px solid #f0f0f0;

  .mark {
    background-color: #f9f9f9;
    // width: 345px;
    min-height: 70px;
    border-radius: 1px;
    margin-top: 15px;
    padding: 12px 14px;
    color: #ccc;
    font-size: 28rpx;
    box-sizing: border-box;
  }

  .mark-msg {
    color: #333;
    font-size: 28rpx;
  }
}

.order-submission .wrapper .item .discount {
  font-size: 30rpx;
  color: #999;
}

.order-submission .wrapper .item .discount input {
  text-align: end;
}

.order-submission .wrapper .item .discount .iconfont {
  color: #515151;
  font-size: 30rpx;
  margin-left: 15rpx;
}

.order-submission .wrapper .item .discount .num {
  font-size: 32rpx;
  margin-right: 20rpx;
}

.order-submission .wrapper .item .shipping {
  font-size: 30rpx;
  color: #999;
  position: relative;
  padding-right: 58rpx;
}

.order-submission .wrapper .item .shipping .iconfont {
  font-size: 35rpx;
  color: #707070;
  position: absolute;
  right: 0;
  top: 50%;
  transform: translateY(-50%);
  margin-left: 30rpx;
}

.order-submission .wrapper .item textarea {
  background-color: #f9f9f9;
  width: 100%;
  height: 135rpx;
  border-radius: 3rpx;
  margin-top: 30rpx;
  padding: 25rpx 28rpx;
  font-size: 28rpx;
  box-sizing: border-box;
}

.order-submission .wrapper .item .placeholder {
  color: #ccc;
  font-size: 28rpx;
}

.order-submission .wrapper .item .list {
  margin-top: 35rpx;
}

.order-submission .wrapper .item .list .payItem {
  border: 1px solid #eee;
  border-radius: 6rpx;
  height: 86rpx;
  width: 100%;
  box-sizing: border-box;
  margin-top: 20rpx;
  font-size: 28rpx;
  color: #282828;
}

.order-submission .wrapper .item .list .payItem.on {
  border-color: #fc5445;
  color: #e93323;
}

.order-submission .wrapper .item .list .payItem .name {
  width: 50%;
  text-align: center;
  border-right: 1px solid #eee;
  padding-left: 80rpx;
}

.order-submission .wrapper .item .list .payItem .name .iconfont {
  width: 44rpx;
  height: 44rpx;
  border-radius: 50%;
  text-align: center;
  line-height: 44rpx;
  background-color: #fe960f;
  color: #fff;
  font-size: 30rpx;
  margin-right: 15rpx;
}

.order-submission .wrapper .item .list .payItem .name .iconfont.icon-weixin2 {
  background-color: #41b035;
}

.order-submission .wrapper .item .list .payItem .name .iconfont.icon-zhifubao {
  background-color: #1677ff;
}

.order-submission .wrapper .item .list .payItem .tip {
  width: 49%;
  text-align: center;
  font-size: 26rpx;
  color: #aaa;
}

.acea-row {
  display: -webkit-box;
  display: -moz-box;
  display: -webkit-flex;
  display: -ms-flexbox;
  display: flex;
  -webkit-box-lines: multiple;
  -moz-box-lines: multiple;
  -o-box-lines: multiple;
  -webkit-flex-wrap: wrap;
  -ms-flex-wrap: wrap;
  flex-wrap: wrap;
}

.acea-row.row-between-wrapper {
  -webkit-box-align: center;
  -moz-box-align: center;
  -o-box-align: center;
  -ms-flex-align: center;
  -webkit-align-items: center;
  align-items: center;
  -webkit-box-pack: justify;
  -moz-box-pack: justify;
  -o-box-pack: justify;
  -ms-flex-pack: justify;
  -webkit-justify-content: space-between;
  justify-content: space-between;
}

.fontC {
  color: grey;
}
</style>
